/*
 * Copyright 2010 Pierre Heinzerling, Uwe Janner, Patrick Wright
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var DEFAULT_POLLING_SEC = 300;

function lsStoreCurrentTheme(theme) {
    ls()["current_theme"] = JSON.stringify(theme);
}

function lsResetCurrentTheme() {
    ls().removeLink("current_theme");
}

function lsGetCurrentTheme() {
    var x = ls()["current_theme"];
    if (x) {
        return JSON.parse(x);
    } else {
        return undefined;
    }
}

function lsHasCurrentTheme() {
    if (lsGetCurrentTheme()) {
        return true;
    } else {
        return false;
    }
}

function lsSetCurrentUserEmail(email) {
    ls()["current_email"] = email;
}

function lsGetOptionsPollingEnabled() {
    var e = ls()["polling_enabled"]
    if (e) {
        return e == "true";
    }
    writeLog("no value for polling enabled, setting");
    ls()["polling_enabled"] = "true";
    return true;
}

function lsSetOptionsPollingEnabled(isEnabled) {
    if (isEnabled) {
        ls()["polling_enabled"] = "true";
    } else {
        ls()["polling_enabled"] = "false";
    }
    writeLog("changing option for polling to " + ls()["polling_enabled"]);
}

function lsSetOptionsPollingTimeSec(sec) {
    writeLog("changing polling time to " + sec);
    ls()["polling_time_sec"] = sec;
}

function lsGetOptionsPollingTimeSec() {
    var sec = ls()["polling_time_sec"];
    if (sec) {
        return sec;
    }
    writeLog("no value for polling time, resetting");
    lsSetOptionsPollingTimeSec(DEFAULT_POLLING_SEC);
    return DEFAULT_POLLING_SEC;
}

function ls() {
    return window.localStorage;
}

function storeHotkeyConfig( hotKey ){
	writeLog("set quick add hotkey to " + hotKey);
	ls().setItem("config_hotkey", hotKey);
}
function loadHotkeyConfig( ){
	return ls().getItem("config_hotkey");
}
